How to do custom search in MySQL?
How to do custom search in MySQL?
421
27-Jul-2023
Aryan Kumar
28-Jul-2023Sure, you can do custom search in MySQL using the
LIKEoperator. TheLIKEoperator allows you to search for a pattern in a column. The syntax is as follows:SQL
The
patterncan be a regular expression or a simple string. For example, the following SQL statement will search for all rows in theproductstable where thenamecolumn contains the word "product":SQL
The
%character is a wildcard that matches any number of characters. So, theLIKEoperator will match all rows where thenamecolumn contains the word "product", regardless of whether the word is at the beginning, end, or middle of the column.Here is an example of how to do custom search in MySQL:
SQL
This will return the following result:
As you can see, the
LIKEoperator has matched all rows where thenamecolumn contains the word "product".Here are some additional things to keep in mind when using the
LIKEoperator:LIKEoperator is case-insensitive by default.ESCAPEkeyword to escape special characters, such as the%character.BINARYkeyword to make theLIKEoperator case-sensitive.